package com.easepal802s.project.ui.presenter;


import android.util.Log;

import com.ogawa.base.Constant.BleConstant;
import com.easepal802s.project.ble.HexUtils;

import com.easepal802s.project.ui.iview.IProfessionalMassageView;
import com.ogawa.base.utils.CommonUtil;

import java.util.Arrays;

/**
 * Created by Yang on 2017/12/13.
 */

public class ProfessionalMassagePresenter extends MBasePresenter {
    IProfessionalMassageView mView;
    private byte mByte5;
    private byte mByte6;
    private byte mByte10;


    public ProfessionalMassagePresenter(IProfessionalMassageView view) {
        mView = view;
    }


    @Override
    public void getDatas(String data) {
        //当前运行的模式
        if (data.startsWith(BleConstant.BAG2_HEAD)) {
            byte[] buffer = HexUtils.hexToByte(data);
            Log.e("getPoints", Arrays.toString(buffer));
            byte byte5 =buffer[5];
            byte byte6 =buffer[6];
            byte byte10 =buffer[10];
            if(mByte5!=byte5||mByte6!=byte6||mByte10!=byte10){
                mByte5 = byte5;
                mByte10 = byte10;
                mByte6 = byte6;

                //上班族
                if(CommonUtil.isOpera(HexUtils.getByteInPosition(data,6,2))){
                    mView.getData(0,0,BleConstant.SHANGBZ);
                }
                //低头
                else if(CommonUtil.isOpera(HexUtils.getByteInPosition(data,6,3))){
                    mView.getData(0,1,BleConstant.DiTZ);

                }
                //开车
                else if(CommonUtil.isOpera(HexUtils.getByteInPosition(data,6,4))){
                    mView.getData(0,2,BleConstant.JIACZ);

                }
                //高跟
                else  if(CommonUtil.isOpera(HexUtils.getByteInPosition(data,6,5))){
                    mView.getData(0,3,BleConstant.GAOGZ);

                }
                //清晨唤醒
                else  if(CommonUtil.isOpera(HexUtils.getByteInPosition(data,5,4))){
                    mView.getData(1,0,BleConstant.QINGCHX);
                }
                //午间小休
                else if(CommonUtil.isOpera(HexUtils.getByteInPosition(data,10,0))){
                    mView.getData(1,1,BleConstant.WUJXX);
                }
                //舒眠模式
                else  if(CommonUtil.isOpera(HexUtils.getByteInPosition(data,5,5))){
                    mView.getData(1,2,BleConstant.SHUMMS);
                }

                //女王美体
                else if(CommonUtil.isOpera(HexUtils.getByteInPosition(data,10,1))){
                    mView.getData(2,0,BleConstant.NVWMT);
                }
                //男士健体
                else  if(CommonUtil.isOpera(HexUtils.getByteInPosition(data,10,2))){
                    mView.getData(2,1,BleConstant.NANSJT);
                }
                //老年模式
                else  if(CommonUtil.isOpera(HexUtils.getByteInPosition(data,5,1))){
                    mView.getData(2,2,BleConstant.LAONMS);
                }

                //速按放松
                else  if(CommonUtil.isOpera(HexUtils.getByteInPosition(data,5,3))){
                    mView.getData(3,0,BleConstant.SUAFS);
                }
                //深度放松
                else if(CommonUtil.isOpera(HexUtils.getByteInPosition(data,6,1))){
                    mView.getData(3,1,BleConstant.SHENDFS);

                }
                //久坐释压
                else if(CommonUtil.isOpera(HexUtils.getByteInPosition(data,10,3))){
                    mView.getData(3,2,BleConstant.JIUZSY);
                }

                //全身舒展
                else if(CommonUtil.isOpera(HexUtils.getByteInPosition(data,5,0))){
                    mView.getData(4,0,BleConstant.QUANSSZ);
                }
                //运动恢复
                else if(CommonUtil.isOpera(HexUtils.getByteInPosition(data,6,0))){
                    mView.getData(4,1,BleConstant.YUNDHF);
                }
                //泰式拉伸
                else  if(CommonUtil.isOpera(HexUtils.getByteInPosition(data,5,2))){
                    mView.getData(4,2,BleConstant.TAISLS);
                }
                else {
                    mView.getData(-1, -1, "00");
                }
                return;

            }
        }

        else  if (data.startsWith(BleConstant.BAG3_HEAD)){
            mView.getData(-1,-1,"00");
        }


    }



}
